const util = require('../../../../utils/util.js');
const api = require('../../../../config/api.js');
const user = require('../../../../services/user.js');

var app = getApp();

Page({
  data: {
    tmCrReqEntitys: []
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数

  },
  onReady: function () {
    // 页面渲染完成

  },
  onShow: function () {
    // 页面显示
    this.getIndexData();
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  getIndexData: function () {
    // 获取用户的登录信息
    // let token = wx.getStorageSync('token');
    // if (token) {
      let that = this;

      util.request(api.MyReagentlist).then(function (res) {
        if (res.code === 0) {
          that.setData({
            tmCrReqEntitys: res.tmCrReqEntitys
          });
        }
      });
    // } else {
    //   wx.navigateTo({
    //     url: "/pages/cr/userCenter/login/login"
    //   });
    // }
  },
  // 我的试剂详情
  myReagentDetail: function (event) {
    // 获取选中下标位置
    let itemIndex = event.currentTarget.dataset.itemIndex;

    // 获取选中归还试剂申请
    let tmCrReqEntity = this.data.tmCrReqEntitys[itemIndex];
    // 转换成json格式
    let dataString = encodeURIComponent(JSON.stringify(tmCrReqEntity));

    wx.navigateTo({
      url: '../myReagentDetail/myReagentDetail?dataString=' + dataString
    })
  }
})